﻿using B.S.RbacData.Domain.Traceabilitys;
using B.S.RbacData.ErrorCode;
using B.S.RbacData.Infrastructure;
using B.S.RbacData.Write.API.Applications.Commands.Traceabilitys;
using MediatR;

namespace B.S.RbacData.Write.API.Applications.Commandhandlters.Traceabilitys
{
    /// <summary>
    /// 逻辑删除图片路径命令处理
    /// </summary>
    public class RemoveImgsCommandhandlter : IRequestHandler<RemoveImgsCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<ImagesModel> imgsRep;

        public RemoveImgsCommandhandlter(IBaseRepository<ImagesModel> ImgsRep)
        {
            imgsRep = ImgsRep;
        }

        public async Task<ApiResult<int>> Handle(RemoveImgsCommand request, CancellationToken cancellationToken)
        {


            var  removeimg= imgsRep.GetAll().FirstOrDefault(x=>x.Id==request.ImgId);
           
            removeimg.IsDel=true;

            await imgsRep.UpdateAsync(removeimg);

            return new ApiResult<int>
            {
                code = ResultEnumCode.Ok,
                data = 1,
                message = "删除成功"


            };
        }
    }
}
